package cn.lg.soar.system.biz.modules.auth.entity;

import cn.lg.soar.common.util.trans.annotations.TranslateName;
import cn.lg.soar.core.annotations.constraints.group.Create;
import cn.lg.soar.core.annotations.constraints.group.Update;
import cn.lg.soar.core.util.easyexcel.converters.BooleanConverter;
import cn.lg.soar.database.base.entity.BaseEntity;
import cn.lg.soar.database.handler.type.IntArrayTypeHandler;
import cn.lg.soar.database.translate.TranslateByEntity;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

/**
 * 组件
 * @author luguoxiang
 * @since 2025-05-03
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Data
@Schema(description = "组件")
@TableName(value = "lg_sys_component", autoResultMap = true)
public class Component extends BaseEntity {

    /**  */
    @NotNull(message = "主键不能为空", groups = { Update.class })
    @ExcelIgnore
    @Schema(description = "主键")
    @TableId(type = IdType.AUTO)
    private Integer id;

    /** 页面id  */
    @Schema(description = "页面id")
    private Integer parentId;

    /** 组件名称 */
    @NotBlank(message = "组件名称不能为空", groups = { Create.class, Update.class })
    @ExcelProperty(value = "组件名称")
    @Schema(description = "组件名称")
    private String name;

    /** 权限码 */
    @NotBlank(message = "权限码不能为空", groups = { Create.class, Update.class })
    @ExcelProperty(value = "权限码")
    @Schema(description = "权限码")
    private String code;

    /** 组件路径 */
    @NotBlank(message = "组件路径不能为空", groups = { Create.class, Update.class })
    @ExcelProperty(value = "组件路径")
    @Schema(description = "组件路径")
    private String path;

    /** 是否共享的 */
    @ExcelProperty(value = "是否共享的", converter = BooleanConverter.class)
    @Schema(description = "是否共享的")
    private Boolean shared;

    /** 是否缓存的 */
    @ExcelProperty(value = "是否缓存的", converter = BooleanConverter.class)
    @Schema(description = "是否缓存的")
    private Boolean keepalive;

    /** 接口权限ids */
    @TranslateName("permits")
    @TranslateByEntity(value = Permit.class)
    @ExcelProperty(value = "接口权限ids")
    @Schema(description = "接口权限ids")
    @TableField(typeHandler = IntArrayTypeHandler.class)
    private Integer[] permitIds;

    @JsonIgnore
    @Override
    public Integer primaryKey() {
        return this.id;
    }

}
